package myJs.myPkg

import japgolly.scalajs.react.callback.Callback
import japgolly.scalajs.react.hooks.Hooks.UseEffectArg

import scala.scalajs.js
import slinky.readwrite.ObjectOrWritten

import scala.scalajs.js.Dynamic.{global => g}
import scala.scalajs.js.annotation.{JSGlobal, JSImport, JSName}

@js.native
@JSImport("bootstrap-sweetalert", JSImport.Default)
object swalRaw extends js.Object {

  def apply(options: ObjectOrWritten[SwalOptions]): Unit = js.native

  def apply(options: ObjectOrWritten[SwalOptions], f: js.Function): Unit = js.native

  def close(): Unit = js.native

}

object swal {

  def apply(options: ObjectOrWritten[SwalOptions]): Unit = swalRaw(options)

  def apply[A](options: ObjectOrWritten[SwalOptions], thunk: => A)(implicit a: UseEffectArg[A]): Unit = {
    swalRaw(options, a.toJs(thunk))
  }

  def close(): Unit = swalRaw.close()

}

case class SwalOptions(
    text: js.UndefOr[String] = js.undefined,
    title: js.UndefOr[String] = js.undefined,
    `type`: js.UndefOr[String] = js.undefined,
    showCancelButton: js.UndefOr[Boolean] = js.undefined,
    showConfirmButton: js.UndefOr[Boolean] = js.undefined,
    confirmButtonClass: js.UndefOr[String] = js.undefined,
    confirmButtonText: js.UndefOr[String] = js.undefined,
    closeOnConfirm: js.UndefOr[Boolean] = js.undefined,
    cancelButtonText: js.UndefOr[String] = js.undefined,
    cancelButtonClass: js.UndefOr[String] = js.undefined,
    showLoaderOnConfirm: js.UndefOr[Boolean] = js.undefined
)
